﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;

namespace myBoard.Framework.Controls.Navigation
{
    public class WEMNextEntitySelected : WeakEventManager
    {
        private static WEMNextEntitySelected _mgr;

        private static WEMNextEntitySelected CurrentManager
        {
            get
            {
                Type mgrType = typeof(WEMNextEntitySelected);
                _mgr = GetCurrentManager(mgrType) as WEMNextEntitySelected;
                if (_mgr == null)
                {
                    _mgr = new WEMNextEntitySelected();
                    SetCurrentManager(mgrType, _mgr);
                }
                return _mgr;
            }
        }

        protected override void StartListening(object source)
        {
            IBreadcrumbExplorerEntity breadcrumbEntity = source as IBreadcrumbExplorerEntity;
            breadcrumbEntity.IBreadcrumbExplorerNextEntitySelected += breadcrumbEntity_IBreadcrumbExplorerNextEntitySelected;
        }        

        protected override void StopListening(object source)
        {
            IBreadcrumbExplorerEntity breadcrumbEntity = source as IBreadcrumbExplorerEntity;
            breadcrumbEntity.IBreadcrumbExplorerNextEntitySelected -= breadcrumbEntity_IBreadcrumbExplorerNextEntitySelected;
        }

        void breadcrumbEntity_IBreadcrumbExplorerNextEntitySelected(IBreadcrumbExplorerEntity source, IBreadcrumbExplorerEntity nextEntity)
        {
            DeliverEvent(source, new BreadcrumbArgs() { Data = nextEntity });
        }

        //static List<IWeakEventListener> _listeners = new List<IWeakEventListener>();

        public static void AddListener(IBreadcrumbExplorerEntity source, IWeakEventListener listener)
        {
            /*if (!_listeners.Contains(listener))
                _listeners.Add(listener);*/

            CurrentManager.ProtectedAddListener(source, listener);            
        }
        public static void RemoveListener(IBreadcrumbExplorerEntity source, IWeakEventListener listener)
        {
            CurrentManager.ProtectedRemoveListener(source, listener);
        }
    }
}
